package com.bsi.core.fdfs;/*
 * Author: liusongs
 * Date: 2020/1/9 11:19
 * Content:
 */

import com.bsi.core.exception.BusinessException;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;

public interface FastDFSHandler {
    /**
     * @param file 需要上传的文件
     * @return 访问路径（可浏览器直接访问）
     * @throws BusinessException
     * @throws FileNotFoundException
     */
    FastResultVo upload(File file) throws BusinessException, FileNotFoundException;

    FastResultVo upload(MultipartFile file) throws BusinessException, IOException;

    /**
     * 删除fastDfs服务器上的文件
     *
     * @param groupPath 上传时返回的groupPath
     * @return 是否删除成功
     */
    boolean delete(String groupPath);

    /**
     * 通过文件url向前台响应流提示下载
     *
     * @param response
     * @param filename 文件名
     * @param attUrl   文件访问路径
     */
    void printStream(HttpServletResponse response, String filename, String attUrl) throws IOException;

    /**
     * @param response
     * @param filename
     * @param attUrl
     * @throws IOException
     */
    void printStream(HttpServletResponse response, String filename, InputStream inputStream) throws IOException;

    /**
     * 上传文件 (存储服务器本地，非文件服务器)
     * @param file
     * @param folder
     * @return
     * @throws IOException
     */
    AttResultVo uploadFile(MultipartFile file, String[] folder) throws IOException;

}
